package com.learn.configuration;

import com.learn.properties.AppPropertiesYml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class WebStaticConfiguration implements WebMvcConfigurer {
    
    @Autowired
    private AppPropertiesYml appProperties;
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 注册静态资源映射
        String fileUploadPath = appProperties.getFileUploadPath();
        if (StringUtils.hasText(fileUploadPath)) {
            registry.addResourceHandler("/upload/**")
                    .addResourceLocations("file:" + fileUploadPath + File.separator);
        }
    }
}
